<template lang="pug">
  kalix-dialog.user-add(title='编辑' bizKey="createexam" ref="kalixBizDialog" v-bind:formModel.sync="formModel" v-bind:targetURL="targetURL")
    div.el-form(slot="dialogFormSlot")
      input(v-model="formModel.paperName" type="hidden")
      input(v-model="formModel.subjectVal" type="hidden")
      el-form-item(label="考试名称" prop="name" v-bind:label-width="labelWidth" v-bind:rules="rules.name")
        el-input(v-model="formModel.name")
      el-form-item(label="考试时间" prop="examStart" v-bind:label-width="labelWidth" v-bind:rules="rules.examStart")
        kalix-datetime-picker(v-model="formModel.examStart" placeholder="请选择考试开始时间" style="width:100%")
      el-form-item(label="考试时长(分钟)" prop="duration" v-bind:label-width="labelWidth")
        el-input-number(v-model="formModel.duration" v-bind:min="5" :max="300")
      el-form-item(label="最少答题时长（分钟）" prop="examMinTime" v-bind:label-width="labelWidth")
        el-input-number(v-model="formModel.examMinTime" v-bind:min="1" :max="300")
      el-form-item(label="考卷模板" prop="paperId" v-bind:label-width="labelWidth" v-bind:rules="rules.paperId")
        kalix-object-select2(v-model="formModel.paperId" v-bind:objectsUrl="paperTagetURL"
        v-bind:label="'title'" v-on:objectSelected="setPaperVal")
      el-form-item(label="及格线" prop="passScore" v-bind:label-width="labelWidth")
        el-input-number(v-model="formModel.passScore" v-bind:min="1" v-bind:max="150")
      el-form-item(label="考试科目" prop="subject" v-bind:label-width="labelWidth")
        el-input(v-model="formModel.subject" v-bind:disabled="true")
      el-form-item(label="考生分配状态" prop="distributeStat" v-bind:label-width="labelWidth")
        el-input(v-model="formModel.distributeStat" v-bind:disabled="true")
      el-form-item(label="教师分配状态" prop="teacherDistribute" v-bind:label-width="labelWidth")
        el-input(v-model="formModel.teacherDistribute" v-bind:disabled="true")
</template>

<script type="text/ecmascript-6">
  import FormModel from './examModel'
  import {ExamCreateURL, ExamPaperURL} from '../config.toml'

  export default {
    name: 'ExamEdit',
    data() {
      return {
        formModel: Object.assign({}, FormModel),
        labelWidth: '180px',
        rules: {
          name: [{required: true, message: '请输入考试名称', trigger: 'blur'}],
          examStart: [{required: true, message: '请选择考试开始时间', trigger: 'blur'}],
          paperId: [{ required: true, message: '请选择考卷模板', trigger: 'change'}]
        },
        targetURL: ExamCreateURL,
        paperTagetURL: ExamPaperURL
      }
    },
    methods: {
      setPaperVal(obj) {
        this.formModel.subject = obj.label
        this.formModel.paperName = obj.title
        this.formModel.subjectVal = obj.value
      }
    }
  }
</script>

<style scoped>

</style>
